﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;

/// <summary>
/// Summary description for DbConnect
/// </summary>
public class DbConnect
{
    public DbConnect()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public string query;
    public string GetResult()
    {
        string rs = string.Empty; 
        using (SqlConnection connection = new SqlConnection())
        {
            connection.ConnectionString = GlobalVar.ConnString;
            connection.Open();
            // Use the connection
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = query;
                command.Connection = connection;
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    //StringBuilder sb = new StringBuilder();
                    //while (reader.Read())
                    //{
                    //    Label1.Text += "<p><pre><a href=''>" + reader.GetString(0) + "</a>         Last Login: </pre></p>";
                    //}
                }
                SqlDataAdapter adapter = new SqlDataAdapter(command.CommandText, connection.ConnectionString);
                DataSet customers = new DataSet();
                adapter.Fill(customers, "user");
                rs += "<count name='row'>"+customers.Tables["user"].Rows.Count+"</count>";
                rs += customers.GetXml();
            }
            connection.Close();
        }
        return rs;
    }
    public void Update()
    {
        using (SqlConnection connection = new SqlConnection())
        {
            connection.ConnectionString = GlobalVar.ConnString;
            connection.Open();
            // Use the connection
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = query;
                command.Connection = connection;
                command.ExecuteNonQuery();
            }
            connection.Close();
        }
    }
}
